package com.th.therp.mapper;

import com.github.pagehelper.Page;
import com.th.therp.pojo.emtity.Inventory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface InventoryMapper {

    Page<Inventory> page(Inventory inventory);

    @Insert("insert into inventory (store_id, material_name, material_barcode, material_category, material_brand, store_name, quantity) VALUES (#{storeId},#{materialName},#{materialBarcode},#{materialCategory},#{materialBrand},#{storeName},#{quantity})")
    void add(Inventory inventory);

    //根据仓库id和商品条码查找商品数量
    @Select("select quantity from inventory where store_id=#{storeId} and material_barcode=#{materialBarcode}")
    Integer findQuantityByStoreIdAndBarcode(Integer storeId, String materialBarcode);

    //根据仓库id和商品条码修改商品数量
    @Update("update inventory set quantity=#{quantity} where store_id=#{storeId} and material_barcode=#{materialBarcode}")
    void updateQuantityByStoreIdAndBarcode(Inventory inventory);

    //根据仓库id查找商品
    @Select("select * from inventory where store_id=#{storeId}")
    List<Inventory> findMaterialOptionsByStoreId(Integer storeId);

    //根据仓库id和商品条码删除库存记录
    @Delete("delete from inventory where store_id=#{storeId} and material_barcode=#{materialBarcode}")
    void deleteByStoreIdAndBarcode(Inventory inventory);

    //根据商品条码查找商品数量
    @Select("select count(quantity) as quantity from inventory where material_barcode=#{materialBarcode}")
    Integer findQuantityByBarcode(String barcode);

    //根据仓库id查找商品数量
    @Select("select count(quantity) as quantity from inventory where store_id=#{storeId}")
    Integer findQuantityByStoreId(Integer storeId);

    //根据仓库ID和商品代码修改库存数量
    @Update("update inventory set quantity=#{quantity} where store_id=#{storeId} and material_barcode=#{materialBarcode}")
    void updateByStoreIdAndBarcode(Integer storeId, String materialBarcode, Integer quantity);
}